package main

import (
	"encoding/json"
	"fmt"
	"sync"

	"lottery/models"
	"lottery/services/lottery/channel/isn99"
)

func main_() {
	agent := &models.Agent{
		LoginName: "shakeme180",
		Passwd:    "aaaa0000",
	}

	simple := new(isn99.ISN99Factory)
	lottery := simple.New(agent)

	var loginResp *models.ActionResp
	for i := 0; i < 3; i++ {
		// 尝试登录三次
		loginResp = lottery.Login() // 登录
		if loginResp.IsSuccess {
			break
		}
	}

	if !loginResp.IsSuccess {
		fmt.Println(loginResp.Msg)
		return
	}

	go lottery.Run()
	games := lottery.GetGames()
	data, _ := json.Marshal(games)
	fmt.Println(string(data))

	gameChan := lottery.GetGames()
	gameDataChan := lottery.GetGameData()
	wg := new(sync.WaitGroup)

	wg.Add(1)
	go func() {
		defer wg.Done()
		for _ = range gameChan {
			// data, _ := json.Marshal(game)
			// fmt.Println(string(data))
		}
	}()

	wg.Add(1)
	go func() {
		defer wg.Done()
		for gameData := range gameDataChan {
			data, _ := json.Marshal(gameData)
			fmt.Println(string(data))
		}
	}()

	wg.Wait()
}
